package ren.xxpure.handler;

import cn.hutool.http.HttpStatus;
import com.alibaba.fastjson.JSON;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import ren.xxpure.entity.CommonResult;
import ren.xxpure.utils.WebUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
	@Override
	public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
		CommonResult<String> result = new CommonResult<>(HttpStatus.HTTP_UNAUTHORIZED, "认证失败");
		String s = JSON.toJSONString(result);

		WebUtils.renderString(response, s);
	}

}
